<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import * as echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize'

const animationDuration = 6000

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '300px'
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')

      this.chart.setOption({
        title : {
          text: '罚款金额',
          subtext: '单位：千',
          x:'center'
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: { // 坐标轴指示器，坐标轴触发有效
            type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
          }
        },
        grid: {
          top: 50,
          left: '2%',
          right: '2%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [{
          type: 'category',
          data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月','8月', '9月', '10月', '11月', '12月'],
          axisTick: {
            alignWithLabel: true
          }
        }],
        yAxis: [{
          type: 'value',
          axisTick: {
            show: false
          }
          // ,
          // axisLabel: {
          //   formatter: '{value}千'
          // }
        }],
        series: [{
          name: '项目处罚',
          type: 'bar',
          stack: 'vistors',
          barWidth: '60%',
          data: [15, 26, 18, 28, 34, 26, 19,38, 26, 19, 18, 35],
          animationDuration
        },
        //  {
        //   name: '车辆处罚',
        //   type: 'bar',
        //   stack: 'vistors',
        //   barWidth: '60%',
        //   data: [80, 52, 200, 334, 390, 330, 220],
        //   animationDuration
        // },
         {
          name: '车辆处罚',
          type: 'bar',
          stack: 'vistors',
          barWidth: '60%',
          data: [16, 22, 18, 26, 15, 19, 15,22, 28, 19, 25, 9.8],
          animationDuration
        }]
      })
    }
  }
}
</script>
